//Header相关的组合式API
import {computed, ref} from "vue";
import {useStore} from 'vuex'
import {useRouter} from 'vue-router'
import {ElMessage} from "element-plus";

export default function () {
    const store = useStore()
    const router = useRouter()

    //退出登录
    function logout(){
        //修改token的值为空
        store.commit('loginStore/UPDATE_TOKEN','')
        //跳转到登录页面
        router.push({name: 'login'})
        ElMessage.info('退出成功！')
    }

    //跳转个人信息页面
    function toUserInfo(){
        router.push({name:'userInfo'})
    }

    return {
        username: computed(() => store.state.loginStore.loginInfo.username),
        todoCount: computed(() => store.state.todoListStore.todoListInfo.backlogNumber),
        logout,toUserInfo
    }
}
